<?php

namespace app\controller\v1;

use app\BaseController;
use app\service\UserService;
use app\service\CryptoService;
use think\App;

class BaseAPIController extends BaseController
{
    protected $userService;
    protected $cryptoService;
    
    public function __construct(App $app)
    {
        //继承父类的构造函数
        parent::__construct($app);
        $this->userService = new UserService();
        $this->cryptoService = new CryptoService();
    }

    /**
     * 成功响应
     */
    protected function success($data = [], string $message = 'success', int $code = 200)
    {
        return json([
            'code' => $code,
            'msg' => $message,
            'data' => $data
        ]);
    }
    
    /**
     * 错误响应
     */
    protected function error(string $message = 'error', int $code = 200)
    {
        return json([
            'code' => $code,
            'msg' => $message,
            'data' => ''
        ]);
    }
}